﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AccurateCollisonCard : CardBase {

    private PolygonCollider2D polygonCollider;
    Vector3[] rangePoints;

    protected override void Awake()
    {
        base.Awake();
        currentTargetScale = 1;
    }

    protected SpriteRenderer SpriteRender
    {
        get {
            return GetComponentInChildren<SpriteRenderer>();
        }
    }

    protected override void Start()
    {
        if (string.IsNullOrEmpty(imagePath)) return;

        StartCoroutine(Res.LoadExternalTexture(imagePath, (tex) => {
            tex.filterMode = FilterMode.Trilinear;
            Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
            SpriteRender.sprite = sprite;
            FixSize(new Vector2(tex.width, tex.height));
            polygonCollider = SpriteRender.gameObject.AddComponent<PolygonCollider2D>();
            lastTex = tex;

            Vector2[] temppoints = polygonCollider.GetPath(0);
            rangePoints = new Vector3[temppoints.Length];
            for (int i = 0; i < temppoints.Length - 1; i++)
            {
                rangePoints[i] = new Vector3(temppoints[i].x, temppoints[i].y, 0);
            }

        }));
    }

    protected override void FixedUpdate()
    {

        //transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one * currentTargetScale, .2f);
    }

    protected override void ReleaseResouces()
    {
        
    }
}
